import { DialogTable } from 'custom/index'
import { getCustomerReceptionPage } from '../api'
import CustomerReceptionDetailColumn from '../component/CustomerReceptionDetailColumn.vue'

const getParams = ctx => {
  const { props } = ctx
  const row = ctx.ctx.attrs.row || {}
  return {
    url: 'DataQueryAnalysis4Detail',
    condition: { userId: row.userId, dateStart: row.dateStart, dateEnd: row.dateEnd, keyword: '' },
    sort: props.sort
  }
}


const customerReceptionDetailDialog = new DialogTable('DialogTable')

customerReceptionDetailDialog
  .title('详情')
  .width('50%')
  .api((data, row) => {
    return getCustomerReceptionPage({
      ...data,
      condition: { userId: row.userId, dateStart: row.dateStart, dateEnd: row.dateEnd, keyword: '' }
    })
  })
  .useSearch().upto('DialogTable')
  .useAuthButton()
    .useItem('').content('导出').exportExcel(getParams).end()
  .upto('DialogTable')
  .useTable()
    .addIndexColumn()
    .useColumn('date').label('日期').width(130).end()
    .useColumn('customGroup').label('客服分组').showOverflowTooltip().minWidth(140).end()
    .useColumn('customTypeName').label('客服类型').minWidth(160).end()
    .useColumn('name').label('客服姓名').minWidth(200).end()
    .useColumn('flowerName').label('客服花名').minWidth(160).end()
    .useColumn('no').label('客服工号').minWidth(200).end()
    .useColumn('sumReceptionVolume').label('总接待量').minWidth(200).sortable().end()
    .useColumn('sumSalesRevenue').label('总销售额').minWidth(200).sortable().end()
    // .useColumn('averageReceptionVolume').label('平均接待量').minWidth(140).end()
    .useColumn('averageConversionRate').label('平均转化率').minWidth(140).sortable().end()
    .useColumn('averageResponseTime').label('平均响应时间').minWidth(140).sortable().end()
    .useColumn('averageQARatio').label('平均问答比').minWidth(140).sortable().end()
    .useColumn('averageResponseRate').label('平均回复率').minWidth(140).sortable().end()
    .useCustomColumn(CustomerReceptionDetailColumn, 'action').label('详情').width(80).fixed('right').end()
    .upto('DialogTable')
  .usePagination()
    .upto('DialogTable')

const detailDetailDialog = new DialogTable('DialogTable')

detailDetailDialog
  .title('详情')
  .width('60%')
  .api((data, row) => {
    return getCustomerReceptionPage({
      ...data,
      condition: { userId: row.userId, dateStart: row.dateStart, dateEnd: row.dateEnd, keyword: '', date: row.date }
    })
  })
  .useTable()
  .addIndexColumn()
    .useColumn('accountName').label('子账号名称').minWidth(150).end()
    .useColumn('customGroup').label('客服分组').showOverflowTooltip().minWidth(140).end()
    .useColumn('customTypeName').label('客服类型').minWidth(160).end()
    .useColumn('name').label('客服姓名').minWidth(200).end()
    .useColumn('flowerName').label('客服花名').minWidth(160).end()
    .useColumn('no').label('客服工号').minWidth(200).end()
    .useColumn('sumReceptionVolume').label('总接待量').minWidth(200).sortable().end()
    .useColumn('sumSalesRevenue').label('总销售额').minWidth(200).sortable().end()
    // .useColumn('averageReceptionVolume').label('平均接待量').minWidth(140).end()
    .useColumn('averageConversionRate').label('转化率').minWidth(140).sortable().end()
    .useColumn('averageResponseTime').label('响应时间').minWidth(140).sortable().end()
    .useColumn('averageQARatio').label('问答比').minWidth(140).sortable().end()
    .useColumn('averageResponseRate').label('回复率').minWidth(140).sortable().end()
    .upto('DialogTable')
  .usePagination()
    .upto('DialogTable')


export default customerReceptionDetailDialog

export {
  detailDetailDialog
}
